package com.library.librarybackend.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.library.librarybackend.domain.dto.UserEditFormDTO;
import com.library.librarybackend.domain.entity.User;
import com.library.librarybackend.domain.enums.GenderEnum;
import com.library.librarybackend.handler.exception.BusinessException;
import com.library.librarybackend.service.UserService;
import com.library.librarybackend.mapper.UserMapper;
import org.springframework.stereotype.Service;

/**
 * @author MR
 * @description 针对表【user(用户表)】的数据库操作Service实现
 * @createDate 2025-09-20 20:41:51
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {

    @Override
    public void edit(UserEditFormDTO userEditFormDTO) {
        // 判断性别是否有
        if (null != userEditFormDTO.getGender() && !GenderEnum.isExist(userEditFormDTO.getGender())) {
            throw new BusinessException("性别不存在");
        }
        User user = BeanUtil.copyProperties(userEditFormDTO, User.class);
        // 更新
        lambdaUpdate()
                .eq(User::getId, userEditFormDTO.getId())
                .update(user);
    }
}




